/*
* HelloMIDlet.java
*/

package HelloSuite;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * The application must extend this class to allow the application
 * management software to control the MIDlet and to be able to retrieve
 * properties from the application descriptor
 */
public class HelloMIDlet extends MIDlet implements CommandListener {

    private Command exitCmd  = new Command("Exit", Command.EXIT, 1);
    private Display display;
    private Form mainForm;

    /**
     * Constructor for the MIDlet,
     * initializations of the form
     */
    public HelloMIDlet(){
    }
    
    /**
     * Signals the MIDlet to terminate and enter the Destroyed state.
     * In the destroyed state the MIDlet must release all resources and
     * save any persistent state
     * @param unconditional If true when this method is called, the
     * MIDlet must cleanup and release all resources.  If false the
     * MIDlet may throw MIDletStateChangeException to indicate
     * it does not want to be destroyed at this time.
     *
     */
    protected void destroyApp(boolean unconditional){
        
    }
    
    /**
     * Signals the MIDlet to enter the Paused state.
     * In the Paused state the MIDlet must release shared resources.
     */
    protected void pauseApp(){
    }
    
    /**
     * Signals the MIDlet that it has entered the Active state
     * The method will only be called when the MIDlet is in the Paused state
     * Performs some initialization, places app in active state
     *@exception MIDletStateChangeException  is thrown if the MIDlet cannot
     * start now but might be able to start at a later time.
     */
    protected void startApp()throws MIDletStateChangeException{
        display = Display.getDisplay(this);
        mainForm = new Form("HelloMIDlet");
        mainForm.addCommand(exitCmd);
        mainForm.setCommandListener(this);
        display.setCurrent(mainForm);
    }
    
    public void commandAction(Command c, Displayable d) {
        if (c == exitCmd) {
            destroyApp(false);
            notifyDestroyed();        
        }    
    }
    
}

